<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="../commons/layui/css/layui.css"/>
</head>
<body>
<form class="layui-form" action="">
    <div class="layui-form-item">
        <label class="layui-form-label">用户名</label>
        <div class="layui-input-inline">
            <input type="text" name="nickName" lay-verify="required" placeholder="请输入用户名" autocomplete="off"
                   class="layui-input nickName">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">手机号码</label>
        <div class="layui-input-inline">
            <input type="text" name="tel" lay-verify="phone" placeholder="请输入号码" autocomplete="off"
                   class="layui-input tel">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">邮箱</label>
        <div class="layui-input-inline">
            <input type="text" name="email" lay-verify="email" placeholder="请输入邮箱" autocomplete="off"
                   class="layui-input email">
        </div>
    </div>
    <div class="layui-form-item" lay-filter="sex">
        <label class="layui-form-label">选择性别</label>
        <div class="layui-input-block">
            <input class="sex" type="radio" name="sex" value="男" title="男">
            <input class="sex" type="radio" name="sex" value="女" title="女">
        </div>
    </div>
    <div class="layui-form-item"><label for="L_city" class="layui-form-label">城市</label>
        <div class="layui-input-inline"><input type="text" id="L_city" name="city" autocomplete="off" value="" class="layui-input city"></div>
    </div>
    <div class="layui-form-item layui-form-text"><label for="L_sign" class="layui-form-label">签名</label>
        <div class="layui-input-block"> <textarea id="L_sign" name="signature" autocomplete="off" class="layui-textarea signature" style="height: 80px;"></textarea></div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"></label>
        <div class="layui-input-inline">
            <input type="button" lay-submit="" lay-filter="userSubmit" value="确认" class="layui-btn">
        </div>
    </div>
    <input type="hidden" name="uId" class="uId"/>
</form>
<script src="../commons/layui/layui.js"></script>
<script>
        layui.use(['form', 'upload', 'element', 'jquery'], function () {
        let $ = layui.jquery
            , form = layui.form
            , upload = layui.upload,
            element = layui.element;
            form.render();
        form.on('submit(userSubmit)', function (data) {
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            let user = data.field;
            $.ajax({
                url: '../user/edit',
                dataType: "json",
                data: {
                    "uId": user.uId,
                    "nickName": user.nickName,
                    "tel": user.tel,
                    "email": user.email,
                    "city":user.city,
                    "sex": user.sex,
                    "signature":user.signature
                },
                success: function (data) {
                    console.log(data+" "+data.code);
                    if (data.code == 0) {
                        parent.layer.close(index); //再执行关闭
                        parent.layui.$(".refresh").click();//通过触发页面局部刷新按钮来刷新父页面更新修改后的表格数据
                        parent.layer.confirm('修改成功');
                    }
                    if (data.code == -1) {
                        layer.msg("登录超时", function () {
                            window.location.href = "../login.html";
                        });
                    }
                    if (data.code == 1) {
                        layer.msg(data.msg);
                    }
                }
            });
            return false;
        });
    });
</script>
</body>
</html>